package model

import (
	"github.com/hajimehoshi/ebiten/v2"
)

type Bg struct {
	*Entity
}

const imgWidth = 1400

var (
	backgroundX  = 0
	backgroundX2 = imgWidth
)

func NewBg() *Bg {
	path := "static/img/bg.png"
	return &Bg{
		NewEntity(path),
	}
}


func Update(config *Config) error {
	backgroundX -= config.BgSpeedFactor
	backgroundX2 -= config.BgSpeedFactor
	if backgroundX < -imgWidth {
		backgroundX = imgWidth
	}
	if backgroundX2 < -imgWidth {
		backgroundX2 = imgWidth
	}
	//// 更新金币位置
	//for i := 0; i < len(coin.coins); i++ {
	//	coin.coins[i].X -= float64(config.BgSpeedFactor)
	//}
	return nil
}


func (bg *Bg) Draw(screen *ebiten.Image) {
	//实现背景图片的移动
	op := &ebiten.DrawImageOptions{}
	//op.GeoM.Scale(0.5, 0.5)
	op.GeoM.Translate(float64(backgroundX), 0)
	screen.DrawImage(bg.img, op)
	op1 := &ebiten.DrawImageOptions{}
	//op1.GeoM.Scale(0.5, 0.5)
	op1.GeoM.Translate(float64(backgroundX2), 0)
	screen.DrawImage(bg.img, op1)
}
